package jk.zmn.test;

import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import jk.zmn.proxy.Admin;
import jk.zmn.proxy.IUserService;
import jk.zmn.proxy.UserService;
import jk.zmn.proxy.proxyclass.CglibProxy;
import jk.zmn.proxy.proxyclass.JDKProxy;
import jk.zmn.proxy.proxyclass.StaticProxy;
import net.sf.cglib.proxy.Enhancer;

public class testProxy {
	
	
	@Test
	public void testStaticProxy(){
		
		//ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationcontext.xml");
		
		StaticProxy staticProxy = new StaticProxy();
		staticProxy.addUser("张三");
		
	}
	
	@Test
	public void testJdkProxy() {
		
		IUserService userService = new UserService();
		
		JDKProxy jdkProxy = new JDKProxy();
		IUserService createProxyInstance = (IUserService)jdkProxy.createProxyInstance(userService);
		createProxyInstance.addUser("李四");
		
	}
	
	@Test
	public void testCglibProxy() {
		CglibProxy cglibProxy = new CglibProxy();
		IUserService proxyInstance = (IUserService)cglibProxy.getProxyInstance(UserService.class);
		proxyInstance.addUser("王五");
		
	}
	
	@Test
	public void testCglib() {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(Admin.class);
		enhancer.setCallback(new CglibProxy());
		Admin admin = (Admin) enhancer.create();
//		CglibProxy cglibProxy = new CglibProxy();
//		Admin admin = (Admin) cglibProxy.getProxyInstance(Admin.class);
		admin.addAdmin("李四");
	}
	
	
	
	
	

}
